package coml.jiyun.hp.zuoye;

import android.os.Bundle;
import com.google.android.material.tabs.TabLayout;
import java.util.ArrayList;
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.FragmentManager;
import coml.jiyun.hp.zuoye.bean.WanBean;
import coml.jiyun.hp.zuoye.fragment.CollectFragment;
import coml.jiyun.hp.zuoye.fragment.RlvHomeFragment;
import coml.jiyun.hp.zuoye.view.WanView;

public class MainActivity extends AppCompatActivity implements WanView {
    private TabLayout mMainTab;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();
    }


    private void initView() {
        mMainTab = (TabLayout) findViewById(R.id.main_tab);

        mMainTab.addTab(mMainTab.newTab().setText("首页"));
        mMainTab.addTab(mMainTab.newTab().setText("收藏"));

        final FragmentManager fragment = getSupportFragmentManager();
        fragment.beginTransaction().replace(R.id.main_fragment,new RlvHomeFragment()).commit();
        mMainTab.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
            @Override
            public void onTabSelected(TabLayout.Tab tab) {
                int position = tab.getPosition();
                if (position==0){
                    fragment.beginTransaction().replace(R.id.main_fragment,new RlvHomeFragment()).commit();
                }else {
                    fragment.beginTransaction().replace(R.id.main_fragment,new CollectFragment()).commit();
                }
            }

            @Override
            public void onTabUnselected(TabLayout.Tab tab) {

            }

            @Override
            public void onTabReselected(TabLayout.Tab tab) {

            }
        });
    }

    @Override
    public void onSuccess(WanBean wanBean) {

    }

    @Override
    public void onFail(String str) {

    }
}